package com.hanhanxiaochong.zhongxiangchuanmei.view.my.act;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.BankCardBean;
import com.hanhanxiaochong.zhongxiangchuanmei.presenter.my.BankCardPresenter;
import com.hanhanxiaochong.zhongxiangchuanmei.util.SharedPreferencesUtil;
import com.hanhanxiaochong.zhongxiangchuanmei.view.base.BaseActivity;
import com.hanhanxiaochong.zhongxiangchuanmei.view.iview.IBankCardView;
import com.hanhanxiaochong.zhongxiangchuanmei.view.my.adapter.BankCardAdapter;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Author : 贾桐
 * E-mail : 653773284@qq.com
 * Time   : 2018/6/11.
 * Desc   : 银行卡activity
 */

public class BankCardActivity extends BaseActivity<BankCardPresenter> implements IBankCardView {
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.recyclerview_bankcard)
    RecyclerView recyclerviewBankcard;

    private BankCardAdapter bankCardAdapter;
    private String token;

    @Override
    protected void initView() {
        setContentView(R.layout.activity_bankcard);
    }

    @Override
    protected void initPresenter() {
        mPresenter = new BankCardPresenter(this);
    }

    @Override
    protected void init() {
        txtTitle.setText("银行卡");
        token = SharedPreferencesUtil.getsInstances(this).getLoginInfo().getToken();
        mPresenter.getBankCards(token);
    }

    @OnClick({R.id.ll_leftview, R.id.ll_add_bankcard})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_leftview:
                finish();
                break;
            case R.id.ll_add_bankcard:
                Intent intent = new Intent(this, AddBankCardActivity.class);
                startActivity(intent);
                break;
        }
    }

    @Override
    public void getBankCards(List<BankCardBean> bankCardBeans) {
        bankCardAdapter = new BankCardAdapter(mContext, R.layout.item_bank_card, bankCardBeans);
        recyclerviewBankcard.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerviewBankcard.setAdapter(bankCardAdapter);
    }
}
